import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    navBarNum: 0,
    // imageHost: 'https://test2.lyhctech.com/russia/',
    // apilink: 'https://test2.lyhctech.com',
    // config: '/russia',
    imageHost: 'https://h5.lifsong365.com/api/',
    apilink: 'https://h5.lifsong365.com',
    config: '/api',
    Local:localStorage.getItem("lang")?localStorage.getItem("lang"):'zh',
    goodsID: localStorage.getItem("goodsID")?localStorage.getItem("goodsID"):'',
    token:localStorage.getItem("token")?localStorage.getItem("token"):'',
    addressForm: localStorage.getItem("addressForm")?JSON.parse(localStorage.getItem("addressForm")):'',
    userInfo: localStorage.getItem("userInfo")?localStorage.getItem("userInfo"):'',
  },
  mutations: {
    setNavBarNum(state,status){
      localStorage.setItem('navBarNum',status);
      state.navBarNum = status;
    },
    setToken(state,status){
      if(status){
        localStorage.setItem("token", status);
        state.token = status;
      } else {
        localStorage.removeItem("token",'');
        state.token = null;
      }
    },
    setUserInfo(state,status){
      if(status){
        localStorage.setItem("userInfo", JSON.stringify(status));
        state.userInfo = status;
      } else {
        localStorage.removeItem("userInfo",'');
        state.userInfo = null;
      }
    },
    setAddressForm(state,status){
      if(status){
        localStorage.setItem("addressForm", status);
        state.addressForm = status;
      } else {
        localStorage.removeItem("addressForm",'');
        state.addressForm = null;
      }
    },
    setGoodsID(state,status){
      if(status){
        localStorage.setItem("goodsID", status);
        state.goodsID = status;
      } else {
        localStorage.removeItem("goodsID",'');
        state.goodsID = null;
      }
    }
  },
  actions: {
  },
  modules: {
  }
})
